package org.springframework.data.redis.core;

/**
 * @Auther: syh
 * @Date: 2020/7/24
 * @Description:
 */
public class JedisBloomFilter<K, V> implements BloomFilter<V> {
    private K key;
    private BloomOperations<K, V> bloomOperations;

    public JedisBloomFilter(K key, double errorRate, long initCapacity, BloomOperations<K, V> bloomOperations) {
        this.key = key;
        this.bloomOperations = bloomOperations;
        try {
            // this.bloomOperations.delete(key);
            this.bloomOperations.createFilter(key, errorRate, initCapacity);
        } catch (Exception e) {
            // ignore
        }
    }

    public Boolean add(V value) {
        return this.bloomOperations.add(this.key, value);
    }

    @SafeVarargs
    public final Boolean[] addMulti(V... values) {
        return this.bloomOperations.addMulti(this.key, values);
    }

    public Boolean exists(V value) {
        return this.bloomOperations.exists(this.key, value);
    }

    @SafeVarargs
    public final Boolean[] existsMulti(V... values) {
        return this.bloomOperations.existsMulti(this.key, values);
    }

    public Boolean delete() {
        return this.bloomOperations.delete(this.key);
    }
}
